﻿var obOne = {};
testArrayOne = [];
timeArray = [];
//obOne.time = [];

function getTimeStamp() {
    var now = new Date();
    return ((now.getMonth() + 1) + '/' + (now.getDate()) + '/' + now.getFullYear() + " " + now.getHours() + ':'
                  + ((now.getMinutes() < 10) ? ("0" + now.getMinutes()) : (now.getMinutes())) + ':' + ((now.getSeconds() < 10) ? ("0" + now
                  .getSeconds()) : (now.getSeconds())));
}


obOne.add = function () {
    "use strict"
    var newItem = document.getElementById("input");
    var holder = {
        taskName: newItem.value,
        userTime: getTimeStamp(),
        isDone: false
    };
    if (newItem.value !== "") {
        testArrayOne.push(holder);
        newItem.value = "";
        obOne.writeItems();
    } else { alert("Type something!") };
}
obOne.clearDone = function () {
    "use strict"
    var holderArray = [];
    for (var x in testArrayOne) {
        if (!testArrayOne[x].isDone) {
            holderArray.push(testArrayOne[x]);
        }
    }
    testArrayOne = holderArray;
    obOne.writeItems();
};
obOne.toggleDone = function (index) {
    "use strict"
    testArrayOne[index].isDone = !testArrayOne[index].isDone;
    obOne.writeItems();
    //document.getElementById("list").innerHTML = (new Date(testArrayOne[index].timeStamp)).toLocaleTimeString();
    //if (testArrayOne[index].isDone) {
    //    obOne.writeItems();
    //} else {
    //    document.getElementById("list").appendChild(new Date(testArrayOne[index].timeStamp).toLocaleTimeString());
    //}

};
obOne.writeItems = function () {
    "use strict"
    var stringHolder = "";
    var tHold = {
        compTime: getTimeStamp()
    };
    timeArray.push(tHold)
    for (var i in testArrayOne) {
        if (testArrayOne[i].isDone) {
            //stringHolder += "<span class='done' onClick='obOne.toggleDone(" + i + ")'>";
            //obOne.time.push(holder2);
            //timerHolder += obOne.time[i]['timer'];S
            stringHolder += "<span class='done' onClick='obOne.toggleDone(" + i + ")'>";
            stringHolder += testArrayOne[i]['taskName'] + " Completed: " + te[i]['compTime'];
            stringHolder += "</span>";
            stringHolder += "<br />";
        } else {
            //obOne.time.pop(holder2);
            stringHolder += "<span class='' onClick='obOne.toggleDone(" + i + ")'>";
            stringHolder += testArrayOne[i]['taskName', 'userTime'];
            stringHolder += "</span>";
            stringHolder += "<br />";
        }
    }
    document.getElementById("list").innerHTML = stringHolder;
    //document.getElementById("list").innerHTML = (new Date(timer[stringHolder].timeStamp)).toLocaleTimeString();
    };